package micro.controller.userMeun;

import com.alibaba.fastjson.JSONObject;
import micro.pojo.employee;
import micro.pojo.employees;
import micro.service.userMeun.userspace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/om")
public class userMenu06 {
    @Autowired
    private micro.service.userMeun.userspace userspace;
    @RequestMapping("/cx")
    public String cx(HttpSession session, HttpServletRequest request, employees employees){

        System.out.println("进入添加");
        int i= userspace.inser(employees);
        if (i>0) {
            System.out.println("增加成功");
            return "redirect:user/order";
        }else {
            System.out.println("增加失败");
            return "userMeun/userList";
        }

    }
    @ResponseBody
    @RequestMapping(value = "/ofa",produces = "text/plain;charset=utf-8",method = RequestMethod.POST)
    public String getMemberById(/*@RequestParam("name") String name,
    @RequestParam("idCard") String idCard, @RequestParam("email1") String email1,
     @RequestParam("phone") String phone,@RequestParam("address") String address,
     @RequestParam("gender") String gender, @RequestParam("beginDate") String beginDate,
    @RequestParam("wordID") String wordID, @RequestParam("workAge") Integer workAge */
            employees employees)
    {
        System.out.println("添加进入");
       /* System.out.println(name);
        employees employees=new employees();
        employees.setName(name);
        employees.setEmail(email1);
        employees.setPhone(phone);
        employees.setAddress(address);
        employees.setBeginDate(beginDate);
        employees.setGender(gender);
        employees.setAddress(address);
        employees.setWorkID(wordID);
        employees.setWorkAge(workAge);*/
        int i=userspace.inser(employees);
        JSONObject result = new JSONObject();
        if(i>0) {
            System.out.println("添加成功");
            System.out.println(employees.getName());
            result.put("status", "success");
        }
        else
        { result.put("status", "fail");
        }
        return result.toJSONString();
    }
}
